home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
IRIX 6.2 Applications 1996 May
/
SGI IRIX 6.2 Applications 1996 May.iso
/
dist
/
impr_dev.idb
/
usr
/
impressario
/
src
/
examples
/
libspool
/
remove.c.z
/
remove.c
Wrap
C/C++ Source or Header
|
1996-05-06
|
3KB
|
141 lines
/**************************************************************************
* *
* Copyright (c) 1991 Silicon Graphics, Inc. *
* All Rights Reserved *
* *
* THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF SGI *
* *
* The copyright notice above does not evidence any actual of intended *
* publication of such source code, and is an unpublished work by Silicon *
* Graphics, Inc. This material contains CONFIDENTIAL INFORMATION that is *
* the property of Silicon Graphics, Inc. Any use, duplication or *
* disclosure not specifically authorized by Silicon Graphics is strictly *
* prohibited. *
* *
* RESTRICTED RIGHTS LEGEND: *
* *
* Use, duplication or disclosure by the Government is subject to *
* restrictions as set forth in subdivision (c)(1)(ii) of the Rights in *
* Technical Data and Computer Software clause at DFARS 52.227-7013, *
* and/or in similar or successor clauses in the FAR, DOD or NASA FAR *
* Supplement. Unpublished - rights reserved under the Copyright Laws of *
* the United States. Contractor is SILICON GRAPHICS, INC., 2011 N. *
* Shoreline Blvd., Mountain View, CA 94039-7311 *
**************************************************************************
*
* File: remove.c
*
* Description: Attempts to remove the specified job(s) from the specified
* printer queue.
*
**************************************************************************/
#ident "$Revision: 1.1 $"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef sgi
#include <getopt.h>
#endif
#include "spool.h"
char *printer;
char *job_id;
int spooler = SL_SPOOLER_NONE;
extern char *optarg;
extern int optind;
void usage(char*);
main(int argc, char *argv[])
{
int ch;
int errflag = 0;
register int i;
/*
* Process command line args
*/
while ((ch = getopt(argc, argv, "d:s:")) != -1) {
switch(ch) {
case 'd': /* Destination printer */
printer = optarg;
break;
case 's': /* Spooler to use */
if (!strcmp(optarg, "bsd"))
spooler = SL_SPOOLER_BSD;
else if (!strcmp(optarg, "sysv"))
spooler = SL_SPOOLER_SYSV;
else
errflag++;
break;
case '?':
default:
errflag++;
break;
}
}
/*
* Get the job_id(s)
*/
if (argc == optind)
errflag++;
else {
for (i = optind; i < argc; i++) {
int len = strlen(argv[i]);
if (job_id)
job_id = (char*)realloc(job_id, strlen(job_id)+len+5);
else {
job_id = (char*)malloc(len + 5);
*job_id = '\0';
}
(void)strcat(job_id, argv[i]);
(void)strcat(job_id, " ");
}
}
/*
* If error print usage and exit
*/
if (errflag) {
usage(argv[0]);
exit(1);
}
/*
* Cancel the job
*/
if (SLCancelJob(job_id, spooler, printer) < 0) {
int j, status, nout;
char **out_buf;
SLPerror(argv[0]);
if ((status = SLGetSpoolerError(&out_buf, &nout)) != 0) {
(void)fprintf(stderr, "Spooler exit status: %d\n", status);
(void)fprintf(stderr, "Spooler error message(s):\n");
for (j = 0; j < nout; j++)
(void)fprintf(stderr, "\t%s\n", out_buf[j]);
}
exit(1);
}
(void)printf("Job cancel request sent\n");
return 0;
}
void usage(char *progname)
{
(void)fprintf(stderr, "%s [-d printer] [-s bsd | sysv] job_id(s)\n",
progname);
}